home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2.0 - Programmer's Utilities Power Pack / Delphi 2.0 Programmer's Utilities Power Pack.iso / a_to_d / delftips / ti2807.asc < prev    next >
Text File  |  1996-09-15  |  5KB  |  183 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.   PRODUCT  :  Delphi                                 NUMBER  :  2807
  8.   VERSION  :  All
  9.        OS  :  Windows
  10.      DATE  :  May 31, 1995                             PAGE  :  1/3
  11.  
  12.     TITLE  :  Loading Bitmaps Into dBASE And Paradox BLOB Fields
  13.  
  14.  
  15.  
  16.  
  17. There are a number of ways to load a bitmap image into the BLOB field of a
  18. dBASE or Paradox table. Three of the easier methods involve 1) copying the
  19. data from the Windows clipboard into a TDBImage component connected to the
  20. BLOB field, 2) using the LoadFromFile method of the TBLOBField component,
  21. and 3) using the Assign method to copy an object of type TBitmap into the
  22. Picture property of a TBDBImage.
  23.  
  24. The first method, copying the bitmap from the clipboard, is probably most
  25. handy when an application needs to add bitmaps to a table when the end-
  26. user is running the application. A TDBImage component is used to act as an
  27. interface between the BLOB field in the table and the image stored in the
  28. clipboard. The PasteFromClipboard method of the TDBImage component is
  29. invoked to copy the bitmap data from the clipboard into the TDBImage. When
  30. the record is posted, the image is stored into the BLOB field in the
  31. table.
  32.  
  33. Because the Windows clipboard can contain data in formats other than just
  34. bitmap, it is advisable to check the format prior to calling the CopyFrom-
  35. Clipboard method. To do this, a TClipboard object is created and its Has-
  36. Format method is used to determine if the data in the clipboard is indeed
  37. of bitmap format. Note that to use a TClipboard object, the Clipbrd unit
  38. must be included in the Uses section of the unit that will be creating
  39. the object.
  40.  
  41. Here is an example showing the contents of the clipboard being copied into
  42. a TDBImage component, if the contents of the clipboard are of bitmap
  43. format:
  44.  
  45.   procedure TForm1.Button1Click(Sender: TObject);
  46.   var
  47.     C: TClipboard;
  48.   begin
  49.     C := TClipboard.Create;
  50.     try
  51.       if Clipboard.HasFormat(CF_BITMAP) then
  52.         DBImage1.PasteFromClipboard
  53.       else
  54.         ShowMessage('Clipboard does not contain a bitmap!');
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.   PRODUCT  :  Delphi                                 NUMBER  :  2807
  69.   VERSION  :  All
  70.        OS  :  Windows
  71.      DATE  :  May 31, 1995                             PAGE  :  2/3
  72.  
  73.     TITLE  :  Loading Bitmaps Into dBASE And Paradox BLOB Fields
  74.  
  75.  
  76.  
  77.  
  78.     finally
  79.       C.Free;
  80.     end;
  81.   end;
  82.  
  83. The second method of filling a BLOB field with a bitmap involves loading
  84. the bitmap directly from a file on disk into the BLOB field. This method
  85. lends itself equally well to uses at run-time for the end-user as for
  86. the developer building an application's data.
  87.  
  88. This method uses the LoadFromFile method of the TBLOBField component, the
  89. Delphi representation of a dBASE for Windows Binary field or a Paradox for
  90. Windows Graphic field, either of which may be used to store bitmap data
  91. in a table.
  92.  
  93. The LoadFromFile method of the TBLOBField component requires a single
  94. parameter: the name of the bitmap file to load, which is of type String.
  95. The value for this parameter may come from a number of sources from the
  96. end-user manually keying in a valid file name to the program providing a
  97. string to the contents of the FileName property of the TOpenDialog comp-
  98. onent.
  99.  
  100. Here is an example showing the use of the LoadFromFile method for a
  101. TBLOBField component named Table1Bitmap (a field called Bitmap in the
  102. table associated with a TTable component named Table1):
  103.  
  104.   procedure TForm1.Button2Click(Sender: TObject);
  105.   begin
  106.     Table1Bitmap.LoadFromFile(
  107.       'c:\delphi\images\splash\16color\construc.bmp');
  108.   end;
  109.  
  110. The third method uses the Assign method to copy the contents of an object
  111. of type TBitmap into the Picture property of a TDBImage component. An
  112. object of type TBitmap might be the Bitmap property of the Picture object
  113. property of a TImage component or it may be a stand-alone TBitmap object.
  114. As with the method copying the data from the clipboard into a TDBImage
  115. component, the bitmap data in the TDBImage component is saved into the
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.   PRODUCT  :  Delphi                                 NUMBER  :  2807
  130.   VERSION  :  All
  131.        OS  :  Windows
  132.      DATE  :  May 31, 1995                             PAGE  :  3/3
  133.  
  134.     TITLE  :  Loading Bitmaps Into dBASE And Paradox BLOB Fields
  135.  
  136.  
  137.  
  138.  
  139. BLOB field in the table when the record is successfully posted.
  140.  
  141. Here is an example using the Assign method. In this case, a stand-alone
  142. TBitmap object is used. To put a bitmap image into the TBitmap, the
  143. LoadFromFile method of the TBitmap component is called.
  144.  
  145.   procedure TForm1.Button3Click(Sender: TObject);
  146.   var
  147.     B: TBitmap;
  148.   begin
  149.     B := TBitmap.Create;
  150.     try
  151.       B.LoadFromFile('c:\delphi\images\splash\16color\athena.bmp');
  152.       DBImage1.Picture.Assign(B);
  153.     finally
  154.       B.Free;
  155.     end;
  156.   end;
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179. DISCLAIMER: You have the right to use this technical information
  180. subject to the terms of the No-Nonsense License Statement that
  181. you received with the Borland product to which this information
  182. pertains.
  183.